{include file="public/_head"}
<!-- Main Container -->
<div class="main-container container-fluid">
    <!-- Page Container -->
    <div class="page-container">

        <!-- Page Sidebar -->
        {include file="public/_left" /}
        <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li class="active">
                        <i class="fa fa-home"></i>&nbsp;日本留学
                    </li>
                    <li>
                        日语培训
                    </li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget radius-bordered">
                            <div class="widget-header bordered-bottom bordered-themeprimary">
                                <span class="widget-caption">留学课程编辑</span>
                            </div>
                            <div class="widget-body">
                                <form class="form-horizontal" method="post" enctype="multipart/form-data" id="form-article-add">

                                    <div class="form-group">
                                        <label for="file1d" class="col-sm-2 control-label no-padding-right">课程配图：</label>
                                        <div class="col-sm-6">
                                            <img src="{$cou.img}" id="plsod" style="{if condition='$cou.img eq null'}display: none;{else}display: block;{/if} border-color:#333;border-style:solid;border-width:0px;" width="100px" height="110px">
                                            <input type="file" id="file1d" name="myFile" />
                                            <input type="hidden" name="id" value="{$cou.id}" />
                                            <input type="hidden" name="img" value="{$cou.img}" />
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="cname" class="control-label col-sm-2 no-padding-right">课程名：</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" id="cname" name="cname" value="{$cou.cname}" placeholder="例：基础日语" />
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="score" class="control-label col-sm-2 no-padding-right">课程评分：</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" id="score" name="score" value="{$cou.score}" placeholder="评分不能为小数且只能是1到5之间的整数" />
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="account" class="control-label col-sm-2 no-padding-right">课程简介：</label>
                                        <div class="col-sm-6">
                                            <textarea type="text"  class="form-control" id="account" name="account" cols="30" rows="5">{$cou.account}</textarea>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="details" class="control-label col-sm-2">课程详情：</label>
                                        <div class="col-sm-6">
                                            <textarea name="details" id="details" cols="30" rows="10">{$cou.details}</textarea>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="button" class="btn btn-primary">更新</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

    </div>
    <!-- /Page Container -->
    <!-- Main Container -->

</div>

{include file='public/_js' /}
<script src="/static/admin/lib/ueditor/ueditor.config.js"></script>
<script src="/static/admin/lib/ueditor/ueditor.all.js"></script>
<script>
    $(function (){
        UE.getEditor('details',{
            /*toolbars: [
                ['fullscreen', 'source', 'undo', 'redo', 'bold']
            ],*/
            /*autoHeightEnabled: true,
            autoFloatEnabled: true,*/
            initialFrameWidth:800,
            initialFrameHeight:270
        });

        //图片预览效果，缓存图片显示
        $("#file1d").change(function(){
            var objUrl = getObjectURL(this.files[0]);
            if (/\w+([.jpg|.png|.gif|.swf|.bmp|.jpeg]){1}$/.test(this.files[0].type)) {
                //var f = document.getElementById("file1d").files[0];
                // 创建对象
                var img = new Image();
                // 改变图片的src
                img.src = objUrl;
                // 加载完成执行
                img.onload = function(){
                    var w = img.width,
                        h = img.height,
                        quotient=w/h;
                    quotient = quotient.toFixed(2);
                    //console.log(quotient);return;
                    /*if(quotient>2 ||quotient<4 ){
                        layer.msg('图片尺寸不对！请上传合格的图片！',{icon:2,time:2000});
                        return;
                    }*/
                    $('#plsod').attr('src',objUrl);
                    if ($('#plsod').src!='') {
                        document.getElementById('plsod').style.display='block';
                    }else{
                        document.getElementById('plsod').style.display='none';
                    }
                }
            }else{
                layer.msg('图片类型必须是gif,jpeg,jpg,png中的一种！',{icon:2,time:1100});
            }
        });

        function getObjectURL(file) {
            var url = null ;
            if (window.createObjectURL!=undefined){ // basic
                url = window.createObjectURL(file) ;
            }else if (window.URL!=undefined) {
                // mozilla(firefox)
                url = window.URL.createObjectURL(file) ;
            }else if (window.webkitURL!=undefined) {
                // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }

        //ajax提交图片
        $('.btn-primary').click(function () {
            var file1d = $('#file1d').val();
            /*if (!file1d){
                layer.msg('图片不能为空！',{icon:5,time:1000});
                return false;
            }*/
            var from = document.getElementById('form-article-add');
            var data = new FormData(from);
            $.ajax({
                url:"{:url('admin/course/course_edit')}",
                type:'post',
                data:data,
                dataType:'json',
                async:false,
                cache:false,
                contentType:false,
                processData:false,
                success:function (data) {
                    if (data.code == 1){
                        layer.msg(data.msg,{
                            icon:6,
                            time:1000
                        },function () {
                            location.href = data.url;
                        });
                    } else {
                        layer.open({
                            title:'课程编辑',
                            content:data.msg,
                            icon:5,
                            anim:6
                        });
                    }
                }
            });
            return false;
        });
    });
</script>

</body>
<!--  /Body -->
</html>
